package com.itheima.d4_proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyUtil {
    public static Star createProxy(BigStar bigstar){
        Star starProxy =(Star) Proxy.newProxyInstance(ProxyUtil.class.getClassLoader(),
                new Class[]{Star.class}, new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if (method.getName().equals("sing")) {
                            System.out.println("准备话筒唱歌");
                        } else if (method.getName().equals("dance")) {
                            System.out.println("准备跳舞");
                        }
                        return method.invoke(bigstar,args);
                    }
                });
        return starProxy;
    }
}

